#include "DoorAcSwitchDetector.h"

#include "LoopManager.h"
#include "ConfigManager.h"
#include "CommandParser.h"


DoorAcSwitchDetector::DoorAcSwitchDetector(DummyChannel& channel, const ExtendDeviceType& deviceType, const std::string& deviceActknowlege): CompoundDevice(channel, deviceType, deviceActknowlege)
, macSwitchDetector(channel, deviceType, deviceActknowlege), mdoorAlertor(channel, deviceType, deviceActknowlege){

    msubDevices.emplace(&ExtendDeviceEnum::AC_SWITCH_DETECTOR, &macSwitchDetector);
    msubDevices.emplace(&ExtendDeviceEnum::DOOR_ALERTOR, &mdoorAlertor);
}



bool DoorAcSwitchDetector::activeUpdateInformation() {
    bool result = macSwitchDetector.updateInformation();
    std::string& switchString = macSwitchDetector.mresponseString;
    if (switchString.empty()){
        result = false;
    } else {
            char firstChar = switchString[0];
            switchString.erase(0, 1);

            mdoorAlertor.commitToTaskPool('1' == firstChar ? DoorStatus::CLOSED : DoorStatus::OPENED);
    }



    return result;
}


bool DoorAcSwitchDetector::updateInformation() {

    return true;
}



bool DoorAcSwitchDetector::initialize() noexcept {
    return macSwitchDetector.initialize();
}


bool DoorAcSwitchDetector::recheck() noexcept {
    return activeUpdateForRecheck();
}


